﻿using System;
using UnityEngine;

namespace QFramework
{
    public abstract class MonoSingle<T> : MonoBehaviour where T : MonoBehaviour
    {
        private static T mInstance;

        public static T Instance
        {
            get
            {
                if (mInstance == null)
                {
                    var o = new GameObject(typeof(T).Name);
                    mInstance = o.AddComponent<T>();
                    GameObject.DontDestroyOnLoad(o);
                }
                return mInstance;
            }
        }
    }

    public class SingleBaseNotMono<T> where T : class
    {
        private static T _instacne;

        public static T Instance
        {
            get
            {
                if (_instacne == null)
                {
                    _instacne = new Lazy<T>(true).Value;
                }
                return _instacne;
            }
        }
    }
}